#include "Login.h"
#include "ui_Login.h"

Login::Login(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Login)
{
    ui->setupUi(this);
    QFile file(":/css/F:/BassCss.qcss");
    // 只读方式打开该文件
    file.open(QFile::ReadOnly);
    // 读取文件全部内容，使用tr()函数将其转换为QString类型
    QString styleSheet = tr(file.readAll());
    //qDebug()<<styleSheet;

    //设置全局样式
    this->setStyleSheet(styleSheet);
    //隐藏外边框
    this->setWindowFlags(Qt::FramelessWindowHint);
    icon.addFile(QStringLiteral(":/img/G:/MaxDatum/mobile/images/logo1.png"), QSize(), QIcon::Normal, QIcon::Off);
    this->setWindowIcon(icon);
    this->setWindowTitle("登录");

//    mainWindow = new MainWindow(this);
//    connect(mainWindow,&MainWindow::quitLoginSingle,this,&Login::quitLogin);
}

Login::~Login()
{
    delete ui;
}
void Login::mousePressEvent(QMouseEvent *event){
    if(event->buttons() == Qt::LeftButton){
        //窗口起始坐标
        startPos = event->globalPos() - this->frameGeometry().topLeft();
    }
}
void Login::mouseMoveEvent(QMouseEvent *event){
    if(event->buttons()==Qt::LeftButton){
        endPos = event->globalPos()- startPos;
        this->move(endPos);
    }
}

void Login::on_btn_login_clicked()
{    
    if(ui->edit_user->text()== QString::fromLocal8Bit("cery") && ui->edit_pass->text() == QString::fromLocal8Bit("cery")){
        this->hide();
        emit loginSingle(ui->edit_user->text(),ui->edit_pass->text());
    }else{
        QMessageBox::information(this, "提示", "用户名或密码错误!");
    }

}

void Login::quitLogin(){
    //mainWindow->hide();
    this->show();
}

void Login::on_close_clicked()
{
    this->close();
    emit exitLogin();
}
